package gameDirector;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
import gameManager.GameManager;
import gameDisplayer.GameDisplayer;

public class GameDirector extends JPanel implements ActionListener {
    private GameManager myGameManager;
    private GameDisplayer myGameDisplayer;
    private Timer time;
    private int trigger = 0;
    
    
    public GameDirector() {
        myGameManager = new GameManager();
        myGameDisplayer = new GameDisplayer(myGameManager);
        time = new Timer(10, this);
        
        addKeyListener(new AL());
        setFocusable(true);
        
        initializeGame();
    }
    
    public void actionPerformed(ActionEvent e){
        if (myGameManager.getCurrentLevel() != null) {
            trigger++;
            
            myGameManager.update(trigger);
            myGameDisplayer.paintGameObjects();
        }
        
        if (isGameOver()) {
            gameOver();
        }
} 
    
    public void initializeGame() {
        myGameDisplayer.displayStartupMenu();
        time.start();
    }
    
    public boolean isGameOver() {
        //Game over conditions
        return false;
    }
    
    public void gameOver() {
        
    }
    
    private class AL extends KeyAdapter{
        public void keyReleased(KeyEvent e){
            myGameManager.keyPressed(e);
        }
        public void keyPressed(KeyEvent e){
            myGameManager.keyReleased(e);
        }
}
}
